﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using MyDB;
using MyClassLibrary;

namespace MyProgram
{
    public partial class FrmExamOverMF : FrmBaseModify
    {
        public FrmExamOverMF()
        {
            InitializeComponent();
        }

        private void FrmExamOverMF_Load(object sender, EventArgs e)
        {
            var qp = from f in db.ExamCategories
                     select f.檢驗類別名稱;

            this.comboBox2.DataSource = qp.ToList();

            var q = (from f in db.ExamOverview
                     where f.檢驗項目ID == drugovIndx
                     select f).First();

            this.label6.Text = q.檢驗項目ID.ToString();
            this.textBox1.Text = q.項目_英文名稱_;
            this.textBox2.Text = q.中文名稱;
            this.comboBox1.SelectedText = q.性別;
            this.textBox4.Text = q.單位;
            this.textBox5.Text = q.檢驗正常值_上限_;
            this.textBox6.Text = q.檢驗正常值_下限_;
            this.textBox7.Text = q.危險百分比.ToString();
            this.comboBox2.SelectedIndex = q.檢驗類別ID - 1;
        }

        MedicareDataClassesDataContext db = new MedicareDataClassesDataContext();

        internal int drugovIndx;

        private void button1_Click(object sender, EventArgs e)
        {
            var q = (from f in db.ExamOverview
                     where f.檢驗項目ID == drugovIndx
                     select f).First();

            q.項目_英文名稱_ = this.textBox1.Text;
            q.中文名稱 = this.textBox2.Text;
            q.性別 = this.comboBox1.SelectedText;
            q.單位 = this.textBox4.Text;
            q.檢驗正常值_上限_ = this.textBox5.Text;
            q.檢驗正常值_下限_ = this.textBox6.Text;
            q.危險百分比 = decimal.Parse(this.textBox7.Text);
            q.檢驗類別ID = this.comboBox2.SelectedIndex + 1;

            db.SubmitChanges();

            this.Close();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
